import { ADD, MINUS } from '../constant'
// import store from './store';

// 创建为Count组件服务的action对象

// 同步action, action值(返回值)为object
// 返回对象时需要小括号包住对象
export const createAddAction = data => ({
    type: ADD, data
});
export const createMinusAction = data => ({
    type: MINUS, data
});

// 异步action, action值(返回值)为function, 可以开启异步任务, 异步action中一般调用同步action
export const createAddAsyncAction = (data, time) => {
    // 回调函数由store调用, 可以直接传dispatch作为参数调用
    return (dispatch) => {
        setTimeout(() => {
            // store.dispatch(createAddAction(data))
            dispatch(createAddAction(data))
        }, time);
    }
}